# coding: utf8

import random

import faker
import numpy as np
import numpy.random as nprand
import sys


def demo_random():
    # random
    print("random.random:")
    print(random.random())

    # randint
    print("random.randint:")
    print(random.randint(10, 20))
    # randrange
    print("random.randrange:")
    print(random.randrange(0, 5, 1))

    # sample
    print("random.sample:")
    print(random.sample([0, 1, 2, 3], 3))

    # choice
    print("random.choices:")
    print(random.choices(list('ab'), k=3))

    # shuffle
    print("random.shuffle:")
    a = list(range(5))
    random.shuffle(a)
    print(a)

    # uniform
    print("random.uniform:")
    print(random.uniform(60, 100))

    # normalvariate
    print("random.gauss:")
    print(random.normalvariate(mu=60, sigma=10))
    print(random.gauss(mu=60, sigma=10))

    # gammavariate
    print("random.gamma:")
    print(random.gammavariate(alpha=1, beta=2))

    # betavariate
    print("random.beta:")
    print(random.betavariate(alpha=1, beta=2))

    # triangular
    print("random.triangular:")
    print(random.triangular(low=1, high=2, mode=1.5))

    # expovariate
    print("random.expovariate:")
    print(random.expovariate(lambd=100))


def demo_numpy_random():
    # rand(d0, ..., dn)生成[0, 1)间形状为(d0, ..., dn)的浮点数随机数数组，默认d0=1
    print("numpy.random.rand(), (3), (3,5):")
    print(nprand.rand())
    print(nprand.rand(3))
    print(nprand.rand(3, 5))
    print('')

    # random_sample(size)生成[0, 1)间大小为size浮点随机数数组，默认size=0
    print("numpy.random_sample(), (3), ((3, 5)):")
    print(nprand.random_sample())
    print(nprand.random_sample(3))
    print(nprand.random_sample((3, 5)))
    print('')

    # random.randint(low, high=None, size=None)生成[low, high)间的整数随机数
    print("numpy.randint(100), (60, 100), (1, 10, (3, 5))")
    print(nprand.randint(100))
    print(nprand.randint(60, 100))
    print(nprand.randint(1, 10, (3, 5)))
    print("")
    # random.random_integer(low, high=None, size=None)生成[low, high]间的整数随机数
    # 等同于randint(low, high+1),
    # so it is deprecated now!
    # print("numpy.random_integers(100), (60, 100), (1, 10, (3, 5))")
    # print(nprand.random_integers(100))
    # print(nprand.random_integers(60, 100))
    # print(nprand.random_integers(1, 10, (3, 5)))
    # print("")

    # 生成[20, 30]间的均匀分布抽样浮点数
    print("random distributions functions:")
    print("numpy.random.uniform(20, 30):")
    print(nprand.uniform(20, 30))
    print('')
    print("numpy.random.randn(d0, d1, ..., dn):")
    print("numpy.random.randn(2, 3):")
    print(nprand.randn(2, 3))
    print('')
    print("numpy.random.normal(loc=0.0, scale=1.0, size=None)")
    print("numpy.random.normal(), (60.5, 5), (500, 100, (3, 3))")
    print(nprand.normal())
    print(nprand.normal(60.5, 5))
    print(nprand.normal(500, 100, (3, 3)))
    print('')
    print("other dist random functions:\n\tnumpy.random.gamma, beta, possion, binomial, exponential, ...")


def task():
    # 输入学生信息
    data1 = []
    student_number = 30
    for j in range(int(student_number)):
        sno = "{:02d}".format(j)
        name = input("请输入原座号{}姓名：".format(sno))
        data1.append((sno, name))
    # 重排位置
    random.shuffle(data1)
    # 生成新座号
    data2 = [(n+1, x[0], x[1]) for n, x in enumerate(data1)]
    # 输出信息
    for x in data2:
        print("考试座号：{}, 姓名：{}， 原座号：{}".format(x[0], x[2], x[1]))


def expand():
    fk = faker.Faker('zh_cn')
    data = []
    for j in range(30):
        data.append([j+1, fk.name()])
    with open("stu74a.csv", "w", encoding='utf8') as fp:
        for d in data:
            fp.write("{},{}\n".format(*d))

    data1 = []
    with open("stu74a.csv", "r", encoding='utf8') as fp:
        for line in fp:
            line = line.replace('\n', '')
            data1.append([s for s in line.split(',')])
    print(data1)

    nprand.shuffle(data1)
    data2 = [(n+1, x[0], x[1]) for n, x in enumerate(data1)]
    # print(data2)
    for x in data2:
        print("考试座号：{}, 姓名：{}， 原座号：{}".format(x[0], x[2], x[1]))


if __name__ == '__main__':
    # demo_random()
    # demo_numpy_random()
    # task()
    expand()
